//
//  CYRichViewController.m
//  CreditAddressBook
//
//  Created by Mosu&Cuu on 15/11/12.
//  Copyright © 2015年 Lee. All rights reserved.
//

#import "CYRichViewController.h"
#import "CYUser.h"
#import "CYLoginHttpTool.h"
#import "UIImageView+WebCache.h"
#import "CYCommon.h"
#import "SDHomeGridView.h"
#import "SDHomeGridItemModel.h"
#import "CYLoanTableVC.h"
#import "CYPayBackDetailTableVC.h"
#import "CYTESTONEViewController.h"
#import "CYTESTTWOViewController.h"
#import "CYTESTTHREEViewController.h"
#import "CYTESTFOREViewController.h"
#import "CYURL.h"


#define kHomeHeaderViewHeight 100

@interface CYRichViewController ()<SDHomeGridViewDeleate>
@property (nonatomic,strong)UIView *headerview;
@property (nonatomic,strong)UIImageView *headerimage;
@property (nonatomic,strong)UILabel *namelab;
@property (nonatomic,strong)UILabel *soucelab;
@property (nonatomic,strong)UILabel *limitlab;
@property (nonatomic,strong)UILabel *paylab;
@property (nonatomic,strong)SDHomeGridView *mainView;
@property (nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation CYRichViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNavigationView];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"财富管理";
    [self creteheaderview];
    [self creatquest];
    [self creteMainView];
    // Do any additional setup after loading the view from its nib.
}
- (void)scanButtonClicked {
    UIViewController *desVc = [[UIViewController alloc] init];
    [self.navigationController pushViewController:desVc animated:YES];
}

//各位请求
-(void)creatquest{
    
    
}

-(void)creteMainView{
    
    SDHomeGridView *mainView = [[SDHomeGridView alloc]init];
    mainView.gridViewDelegate = self;
    mainView.showsHorizontalScrollIndicator = NO;
    NSMutableArray *temp = [NSMutableArray array];

    SDHomeGridItemModel *model0 = [SDHomeGridItemModel alloc];
    model0.destinationClass = [CYTESTONEViewController class];
    model0.imageResString = [NSString stringWithFormat:@"i00"];
    model0.title = @"信用";
    [temp addObject:model0];
    
    SDHomeGridItemModel *model1 = [SDHomeGridItemModel alloc];
    model1.destinationClass = [CYTESTTWOViewController class];
    model1.imageResString = [NSString stringWithFormat:@"i01"];
    model1.title = @"额度";
    [temp addObject:model1];
    
    SDHomeGridItemModel *model2 = [SDHomeGridItemModel alloc];
    model2.destinationClass = [CYTESTTHREEViewController class];
    model2.imageResString = [NSString stringWithFormat:@"i02"];
    model2.title = @"还款";
    [temp addObject:model2];
    
    SDHomeGridItemModel *model3 = [SDHomeGridItemModel alloc];
    model3.destinationClass = [CYTESTFOREViewController class];
    [temp addObject:model3];
    model3.imageResString = [NSString stringWithFormat:@"i03"];
    model3.title = @"积分";
    
    _dataArray = [temp copy];
    mainView.gridModelsArray = [ temp copy];
    
    [self.view addSubview:mainView];
    _mainView = mainView;

}
-(void)creteheaderview{
       _headerview = [[UIView alloc]initWithFrame:CGRectMake(0, 64, self.view.width, self.view.height/4)];
    _headerview.backgroundColor = CYColor(34, 192, 228, 1);
       //头部视图
    [self.view addSubview:_headerview];
    //头像视图
    [self headimageview];
    //名字视图
    [self nameview];
    //其他视图
    [self otherview];
    
}

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    
    CGFloat headerY = 0;
    headerY = ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) ? 64 : 0;
    _mainView.frame = CGRectMake(0, _headerview.y + _headerview.height, self.view.width, self.view.height - kHomeHeaderViewHeight);
}

-(void)headimageview{
    
   _headerimage = [[UIImageView alloc] initWithFrame:CGRectMake(_headerview.x+30, _headerview.y+30, _headerview.height/1.8, _headerview.height/1.8)];
    
    _headerimage.layer.cornerRadius = _headerimage.width/2;
    _headerimage.clipsToBounds = YES;
    _headerimage.backgroundColor = [UIColor grayColor];
    CYUser *user = [CYLoginHttpTool userData].user;
    if (user.headPic) {
        [_headerimage sd_setImageWithURL:CYURLWithUserService(user.headPic) placeholderImage:nil];
    }
    [self.view addSubview:_headerimage];
    
}

-(void)nameview{
    UILabel *namelab = [[UILabel alloc]initWithFrame:CGRectMake(_headerimage.x,_headerimage.y+_headerimage.height+10, _headerimage.width, 20)];
    namelab.textAlignment = NSTextAlignmentCenter;
    namelab.textColor = [UIColor whiteColor];
    namelab.font = [UIFont systemFontOfSize:14];
    namelab.layer.cornerRadius = 10.0f;
    //namelab.layer.borderWidth = 0.8;
    //namelab.layer.borderColor = [UIColor whiteColor].CGColor;
    //namelab.backgroundColor = CYColor(131, 195, 111, 1);
    
    CYUser *user = [CYLoginHttpTool userData].user;
    if (user.nickName) {
        namelab.text = user.nickName;
    } else {
        namelab.textColor = [UIColor grayColor];
        namelab.text = @"未填写昵称";
    }
    [self.view addSubview:namelab];
}

-(void)otherview{
    _soucelab = [[UILabel alloc]initWithFrame:CGRectMake(self.view.width/3, _headerview.height/2.5+64, self.view.width/5 ,15)];
    _limitlab = [[UILabel alloc]initWithFrame: CGRectMake(_soucelab.x, _soucelab.y+_soucelab.height+10, _soucelab.width, _soucelab.height)];
    _paylab = [[UILabel alloc] initWithFrame:CGRectMake(_soucelab.x, _limitlab.y+_limitlab.height+10, _soucelab.width, _soucelab.height)];
    NSString *ssour = @"1000";
    NSString *limit = @"500000.00";
    NSString *pay= @"790.50";
    _soucelab.textColor = [UIColor whiteColor];
    _limitlab.textColor = [UIColor whiteColor];
    _paylab.textColor = [UIColor whiteColor];
    _soucelab.font = [UIFont systemFontOfSize:12];
    _limitlab.font = [UIFont systemFontOfSize:12];
    _paylab.font = [UIFont systemFontOfSize:12];
    _soucelab.text = [NSString stringWithFormat:@"积分: %@",ssour];
    _limitlab.text = [NSString stringWithFormat:@"额度: %@",limit];
    _paylab.text   = [NSString stringWithFormat:@"还款: %@",pay];
    
    [self.view addSubview:_soucelab];
    [self.view addSubview:_limitlab];
    [self.view addSubview:_paylab];
}

#pragma mark - SDHomeGridViewDeleate
- (void)homeGrideView:(SDHomeGridView *)gridView selectItemAtIndex:(NSInteger)index {
   SDHomeGridItemModel *model = _dataArray[index];
    UIViewController *vc = [[model.destinationClass alloc] init];
    //vc.title = model.title;
        //vc.view.backgroundColor = [UIColor redColor];
    [self.navigationController pushViewController:vc animated:YES];

}

- (void)homeGrideViewmoreItemButtonClicked:(SDHomeGridView *)gridView {
   
    
}

- (void)homeGrideViewDidChangeItems:(SDHomeGridView *)gridView {
   [self creteMainView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
